<?php
/************************FoxPHP威客系统************************/
/*                                                            */
/*  FoxPHP.Com (C)2006-2016 FoxPHP Inc.                       */
/*  This is NOT a freeware, use is subject to license terms   */
/*  FoxPHP威客系统是商业软件,使用于商业用途请购买授权         */
/*  V3.0 2016.3                                               */
/*  foxphp@aliyun.com                                         */
/*  http://www.foxphp.com                                     */
/*                                                            */
/**************************************************************/

namespace Admin\Controller;
use Think\Controller;
class MemberController extends IndexController {
	
	//列表动作-----------------------------------------------------------------------------------------------
	public function indexAction(){
		
		$model=new \Admin\Model\MemberModel();
		
		foreach($model->IndexGetData(
				//排序
				array(
					array('order'=>'uid','name'=>'	UID'),
					array('order'=>'username','name'=>'用户名'),
					array('order'=>'email','name'=>'邮箱'),
					array('order'=>'realname','name'=>'实名认证'),
					array('order'=>'typename','name'=>'帐号类型'),
					array('order'=>'groupname','name'=>'用户组名'),
					array('order'=>'vipendtime','name'=>'用户组过期时间'),
					array('order'=>'money','name'=>'可用金额'),
					array('order'=>'moneyin','name'=>'总收入金额'),
					array('order'=>'moneyout','name'=>'总支出金额'),
					array('order'=>'unionid','name'=>'推广员UID'),
					array('order'=>'unionname','name'=>'推广员用户名'),
					array('order'=>'uniontime','name'=>'推广员过期时间'),
					array('order'=>'top','name'=>'推荐'),
					array('order'=>'dateline','name'=>'注册时间'),
					array('order'=>'provid','name'=>'地区')
					
				),
				//查询
				array(	
					'username'=>array('username','string'),
					'uid'=>array('uid','int'),
					'unionid'=>array('unionid','int'),
					'usergroup'=>array('usergroup','int'),
					'cityid'=>array('cityid','city')
				)
				
			) as $key=>$value){
			$this->assign($key,$value);
		}
		
		$category=array();
		if(!empty($_GET['catid'])){
			$catid=intval($_GET['catid']);
			$categoryarr=M('Category')->token(false)->where(" catid=$catid ")->find();
			if(!empty($categoryarr['catid'])){
				$category['category_name_1']=$categoryarr['name'];
				$upid=$categoryarr['upid'];
				$categoryarr=M('Category')->token(false)->where(" catid=$upid ")->find();
				if(!empty($categoryarr['catid'])){
					$category['category_name_2']=$categoryarr['name'];
					$upid=$categoryarr['upid'];
					$categoryarr=M('Category')->token(false)->where(" catid=$upid ")->find();
					if(!empty($categoryarr['catid'])){
						$category['category_name_3']=$categoryarr['name'];
					}
				}
			}
		}
		
		$this->assign('category',$category);

		$usergrouparr=M('AuthGroup')->token(false)->select();
		$this->assign('usergrouparr',$usergrouparr);
		$this->display();
	}
	
	//用户操作-----------------------------------------------------------------------------------------------
	public function operateAction(){
		
		//TOP------------------------------------------ 
		 $tasktop=0;
		 
		 if(!empty($_POST['SetTop'])){  

				$tasktop=1;
		 }
		 
		 if(!empty($_POST['SetTop']) || !empty($_POST['CloseTop'])){   
		 
				$ids=GetCheckBox($_POST['checkbox']);
				
				if($ids){
	
					M('Member')->where(" uid IN($ids) ")->save(array('top'=>$tasktop));
			
					$refresh='设置成功！';
				}else{
					$refresh='没有数据提交！';
				}
		}else{
			
			$ids=GetCheckBox($_POST['checkbox']);
		  
			if($ids){
				
				M('Member')->token(false)->where(" uid IN($ids) ")->delete();

				$refresh.='<p>'.$ids.'用户删除成功！</p>';

			}else{

				$refresh='<p>请选操作数据！</p>';

			}
		}
		
		$this->error($refresh,U(MODULE_NAME.'/'.CONTROLLER_NAME.'/index'),3);
		
	}
	
	//修改动作-----------------------------------------------------------------------------------------------
	public function editAction(){
		$id=I('get.id',0,'int');
		$model=new \Admin\Model\MemberModel();
		$manage=$model->token(false)->where(" uid=$id ")->find();
		if(!$manage['uid']){
			$this->error('修改数据不存在!',U(MODULE_NAME.'/'.CONTROLLER_NAME.'/index'),3);
		}
			
		if(IsPost('Submit')){
			$model->token(false)->where(" uid=$id ")->save($model->FormatData());
			$this->error('修改成功!',U(MODULE_NAME.'/'.CONTROLLER_NAME.'/edit/id/'.$id),3);
		}else{
			$usergrouparr=M('AuthGroup')->token(false)->select();
			$this->assign('usergrouparr',$usergrouparr);
			$this->assign('manage',$manage);
			$this->assign('id',$manage['uid']);
			$this->display('Member:add');
		}
		
	}
	
	//删除动作-----------------------------------------------------------------------------------------------
	public function deleteAction(){
		$model=new \Admin\Model\MemberModel();
		$result=$model->DeleteData('uid');
		$this->error($result['message'],U(MODULE_NAME.'/'.CONTROLLER_NAME.'/index'),3);
	}
	
}